//
//  ViewController.swift
//  PersonalAssistant
//
//  Created by zk on 2025/3/11.
//

import UIKit

class ViewController: UIViewController {
    var tableView: UITableView = UITableView(frame: CGRectZero, style: .grouped);
    var dataSource: [String] = [
        "Collection"
    ]
    var descArr: [String] = [
        "Feature: collection view diffable datasource"
    ]
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.title = "Demo"
        setupChildren()
    }
    func setupChildren() {
        tableView.frame = view.bounds
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "UITableViewCell")
        view.addSubview(tableView)
    }
}
extension ViewController: UITableViewDelegate, UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataSource.count
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 70
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell")!
        //
        var configuration = cell.defaultContentConfiguration()
        configuration.image = UIImage(systemName: "star")
        configuration.imageProperties.tintColor = .orange
        configuration.text = self.dataSource[indexPath.row]
        configuration.secondaryText = self.descArr[indexPath.row]
        configuration.secondaryTextProperties.color = .gray
        cell.contentConfiguration = configuration
        cell.accessoryType = .disclosureIndicator
        //
//        if #available(iOS 18.0, *) {
//            var bgConfig = UIBackgroundConfiguration.listCell()
//            bgConfig.backgroundColor = .systemGray6
//            cell.backgroundConfiguration = bgConfig
//        } else {
//            var bgConfig = UIBackgroundConfiguration.listPlainCell()
//            bgConfig.backgroundColor = .systemGray6
//            cell.backgroundConfiguration = bgConfig
//        }
        return cell
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        if (0 == indexPath.row) {
            self.navigationController!.pushViewController(HCollectionPage(), animated: true)
        }
    }
}

